/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-22
 * Time: 12:38
 */
class A {
    /*public<E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }*/
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test {
    public static void main(String[] args) {
        Integer[] arr = new Integer[]{1,2,3,4,5,100,234,23,12,4,56};
        int ret = A.findMax(arr);//通过传入的参数会自动推导出泛型方法中E类型
        //等价于int ret = a.<Integer>findMax(arr);
        System.out.println(ret);
    }
    /*public static void main(String[] args) {
        Integer[] arr = new Integer[]{1,2,3,4,5,100,234,23,12,4,56};
        A a = new A();
        int ret = a.findMax(arr);//通过传入的参数会自动推导出泛型方法中E类型
        //等价于int ret = a.<Integer>findMax(arr);
        System.out.println(ret);
    }*/
}
